home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / ab20 / unarced / graphics / anim / playanim.c < prev    next >
C/C++ Source or Header  |  1995-03-17  |  6KB  |  248 lines

  1.  
  2. /* PlayAnim.c
  3.  *
  4.  * Load an ILBM raster image file from C structures in memory
  5.  * into an existing bitmap (preloaded files from PreLoadAnim).
  6.  * 
  7.  * Written by Gary Bonham, Sparta, Inc.  15 Aug 1986
  8.  *
  9.  */
  10.  
  11. #include "intuall.h"
  12. #include "libraries/dos.h"
  13. #include "libraries/dosextens.h"
  14. #include "ilbm.h"
  15. #include "readpict.h"
  16. #include "putanim.h"
  17. #include "preloadanim.h"
  18. #include "dbview.h"
  19. #include "functions.h"
  20. #include "stdio.h"
  21.  
  22. ULONG Bits;
  23. WORD *ytable,table[500];
  24. extern int loopplay,continuousplay;
  25. int phase = 0;
  26. extern int Pop;
  27. extern int Active_View,Display_View;
  28. extern struct DBView DBView[];
  29. static BitMapHeader masterbmhd;
  30.  
  31. /* ============================================================ */
  32.  
  33. PlayAnim(fileptr,ii,Nn)
  34. int ii,Nn;
  35. struct IFFfile *fileptr;
  36. {
  37.    char c;
  38.    int nn,i,anim;
  39.    struct FrameHD *currentframe;
  40.    struct BitMap *bm;
  41.    UWORD mod;
  42.    int maxtime,notimes;
  43.  
  44.    maxtime = notimes = 0;
  45.    if (--ii < 0) ii = 0;
  46.    anim = 0;
  47.    currentframe = fileptr->firstframe;
  48.    Pop = 0;
  49.    if (phase) {
  50.       anim = 1;
  51.       currentframe = currentframe->next->next;
  52.    }
  53.    else phase = 1;
  54.  
  55.    while (currentframe) {
  56.       bm = &DBView[Active_View].BitMap;
  57.       if (anim == 0) {
  58.          if (currentframe->bmhd) {
  59.             SetBMHD(bm,currentframe);
  60.             DBView[Active_View].DWidth =
  61.                DBView[Display_View].DWidth = currentframe->bmhd->pageWidth;
  62.             DBView[Active_View].DHeight =
  63.                DBView[Display_View].DHeight = currentframe->bmhd->pageHeight;
  64.             DBView[Active_View].Depth =
  65.                DBView[Display_View].Depth = currentframe->bmhd->nPlanes;
  66.             DBView[Active_View].DxOffset = DBView[Display_View].DxOffset = 0;
  67.             DBView[Active_View].DyOffset = DBView[Display_View].DyOffset = 0;
  68.             if (currentframe->camg) {
  69.                mod = currentframe->camg->ViewModes;
  70.             }
  71.             else {
  72.                mod = 0;
  73.                if (currentframe->bmhd->pageWidth >= 640) mod |= HIRES;
  74.                if (currentframe->bmhd->pageHeight>= 400) mod |= LACE;
  75.             }
  76.             DBView[Active_View].Modes = DBView[Display_View].Modes = mod;
  77.             DBView[Active_View].nColorRegs =
  78.                DBView[Display_View].nColorRegs = 32;
  79.             for (i=0;i<32;i++) 
  80.                DBView[Active_View].colorMap[i] =
  81.                   DBView[Display_View].colorMap[i] = 0;
  82.          }
  83.          else GoodBye("First frame must have BMHD");
  84.       }
  85.       else if (currentframe->bmhd) SetBMHD(bm,currentframe);
  86.       if (currentframe->anhd) SetANHD(bm,currentframe);
  87.       if (currentframe->nColorRegs) SetCMAP(bm,currentframe);
  88.       if (Pop >= 2) {
  89.          if (currentframe->body) {
  90.             if (Pop == 5) SetRIFF(bm,currentframe);
  91.             else GoodBye("illegal op value for delta mode");
  92.          }
  93.       }
  94.       else {
  95.          if (currentframe->body) SetBODY(bm,currentframe);
  96.       }
  97.       DBflip();
  98.       Chk_Abort();
  99.       if (anim == 0) {
  100.          DBCopy(Active_View,Display_View);
  101.          anim++;
  102.          if (ii == 0) phase = 0;
  103.       }
  104.       if (currentframe) currentframe = currentframe->next;
  105.     }
  106.    if (ii <= 1) {
  107.       phase = 0;
  108.       return(0);
  109.    }
  110.    else return(ii);
  111. }
  112.  
  113. SetBMHD(bm,cfr)
  114. struct BitMap *bm;
  115. struct FrameHD *cfr;
  116. {
  117.    LONG plsize;
  118.    int i;
  119.  
  120.    InitBitMap(bm,(long)cfr->bmhd->nPlanes
  121.                 ,(long)cfr->bmhd->w
  122.                 ,(long)cfr->bmhd->h);
  123.    plsize = (long)RowBytes(cfr->bmhd->w)
  124.           * (long)cfr->bmhd->h;
  125.    for (i=0;i<cfr->bmhd->nPlanes;i++) {
  126.       bm->Planes[i] = DBView[Active_View].plane0 + plsize*i;
  127.    }
  128.    masterbmhd = *cfr->bmhd;
  129.    return(0);
  130. }
  131.  
  132. SetCMAP(bm,cfr)
  133. struct BitMap *bm;
  134. struct FrameHD *cfr;
  135. {
  136.    int i;
  137.    for (i=0;i<cfr->nColorRegs;i++) {
  138.       DBView[Active_View].colorMap[i] = cfr->cmap[i];
  139.    }
  140.    return(0);
  141. }
  142.  
  143. SetANHD(bm,cfr)
  144. struct BitMap *bm;
  145. struct FrameHD *cfr;
  146. {
  147.    Pop = cfr->anhd->operation;
  148.    Bits= cfr->anhd->bits;
  149.    return(0);
  150. }
  151.  
  152. /*** SetRIFF(bm,cfr) ***/
  153.  
  154. SetRIFF(bm,cfr)
  155. struct BitMap *bm;
  156. struct FrameHD *cfr;
  157. {
  158.    register int j,jmax;
  159.    int i,nBpR;
  160.    unsigned char *ptr;
  161.    LONG *deltadata;
  162.    register unsigned char *deltabyte;
  163.  
  164.    nBpR = bm->BytesPerRow;
  165.    make_ytable(nBpR<<3,bm->Rows);
  166.    deltadata = (LONG *)cfr->body;
  167.    for (i=0;i<6;i++) {
  168.       if (deltadata[i]) {
  169.          deltabyte = (unsigned char *)deltadata + deltadata[i];
  170.          ptr = (unsigned char *)(bm->Planes[i]);
  171.          decode_vkplane(deltabyte,ptr,(long)nBpR);
  172.       }
  173.    }
  174.    return(0);
  175. }
  176.  
  177. /*** make_ytable(width,height) ***/
  178.  
  179. make_ytable(width,height)
  180. WORD width,height;
  181. {
  182.    register WORD linebytes,*pt,acc;
  183.  
  184.    linebytes = (((width+15) >>4) <<1);
  185.    ytable = &table[0];
  186.    pt = ytable;
  187.    acc = 0;
  188.    while (--height >= 0) {
  189.       *pt++ = acc;
  190.       acc += linebytes;
  191.    }
  192.    return(1);
  193. }
  194.  
  195. SetBODY(bm,cfr)
  196. struct BitMap *bm;
  197. struct FrameHD *cfr;
  198. {
  199.    UWORD w,h;
  200.    LONG x,y;
  201.    UBYTE mask;
  202.    register long deltabyte;
  203.    long i,irow;
  204.    register long ip;
  205.    BYTE *planes[6],*ss;
  206.    register BYTE **dd;
  207.    register WORD srcRowBytes;
  208.  
  209.    if (cfr->anhd) {
  210.       w = cfr->anhd->w;
  211.       h = cfr->anhd->h;
  212.       x = cfr->anhd->x;
  213.       y = cfr->anhd->y;
  214.       mask = cfr->anhd->mask;
  215.    }
  216.    else {
  217.       w = cfr->bmhd->w;
  218.       h = cfr->bmhd->h;
  219.       x = cfr->bmhd->x;
  220.       y = cfr->bmhd->y;
  221.       mask = 0xFF;
  222.    }
  223.  
  224.    srcRowBytes = RowBytes(w);
  225.    deltabyte = (masterbmhd.pageWidth>>3) - (w>>3);
  226.  
  227.    /* assume cmpByteRun1 data compression */
  228.    for (i=0;i<6;i++) {
  229.       if ((mask >>i) &1) planes[i] = (BYTE *)bm->Planes[i]
  230.                                    + y * bm->BytesPerRow + (x>>3);
  231.       else planes[i] = NULL;
  232.    }
  233.  
  234.    ss = (BYTE *)cfr->body;
  235.  
  236.    for (irow = h;irow>0;irow--) {
  237.       for (ip=0;ip<masterbmhd.nPlanes;ip++) {
  238.          if (planes[ip]) {
  239.             dd = &planes[ip];
  240.             UnPackRow(&ss,dd,10000,srcRowBytes);
  241.             planes[ip] += deltabyte;
  242.          }
  243.       }
  244.    }
  245.    return(0);
  246. }
  247.  
  248.